package com.kai.steering.data.service.entity.vo;

import com.kai.steering.data.service.entity.domainObject.KnowledgeDO;
import com.kai.steering.data.service.entity.domainObject.TestDO;
import com.kai.steering.data.service.entity.domainObject.WarehouseDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <pre>
 * 仓库 VO对象
 * </pre>
 *
 * @author kai
 * @date 2022-02-23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "WarehouseVO对象", description = "仓库业务视图")
public class WarehouseVO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "仓库id")
    private String warehouseId;
    @ApiModelProperty(value = "仓库名")
    private String warehouseName;
    @ApiModelProperty(value = "上级仓库")
    private String warehouseSuperior;
    @ApiModelProperty(value = "仓库信息")
    private String warehouseInformation;
    @ApiModelProperty(value = "创建时间")
    private Date creationDatetime;
    @ApiModelProperty(value = "管理员id或者用户id")
    private String founder;
    @ApiModelProperty(value = "级别")
    private Integer level;

    @ApiModelProperty(value = "下级仓库")
    private List<WarehouseVO> childWarehouses;
    @ApiModelProperty(value = "知识点分类")
    private List<KnowledgeVO> knowledgeVOS;
    @ApiModelProperty(value = "试卷")
    private List<TestVO> testS;

    public WarehouseVO(WarehouseDO warehouseDO) {
        this.convertWarehouseVO(warehouseDO);
    }

    public WarehouseVO convertWarehouseVO(WarehouseDO warehouseDO){
        this.warehouseId=warehouseDO.getWarehouseId();
        this.warehouseName=warehouseDO.getWarehouseName();
        this.warehouseSuperior=warehouseDO.getWarehouseSuperior();
        this.warehouseInformation=warehouseDO.getWarehouseInformation();
        this.creationDatetime=warehouseDO.getCreationDatetime();
        this.founder=warehouseDO.getFounder();
        this.level=warehouseDO.getLevel();
        this.childWarehouses=null;
        if (warehouseDO.getChildWarehouses()!=null){
            this.childWarehouses=warehouseDO.getChildWarehouses().stream().map(warehouseDO1 ->{
                return new WarehouseVO(warehouseDO1);
            }).collect(Collectors.toList());
        }
        if (warehouseDO.getKnowledges()!=null){
            this.knowledgeVOS=warehouseDO.getKnowledges().stream().map(knowledgeDO -> {
                return new KnowledgeVO(knowledgeDO);
            }).collect(Collectors.toList());
        }
        if (warehouseDO.getTestS()!=null) {
            this.testS=warehouseDO.getTestS().stream().map(testDO -> {
                return new TestVO(testDO);
            }).collect(Collectors.toList());
        }
        return this;
    }
}